#lang racket


(provide svn-update)


(define (process-in proc)
  (second proc))

(define (process-out proc)
  (first proc))

(define (process-error proc)
  (fourth proc))

(define (process-fn proc)
  (fifth proc))


(define (svn-process command fn)
  (let ((proc (process command)))
    (let ((proc-in (process-in proc))
          (proc-out (process-out proc))
          (proc-error (process-error proc))
          (proc-fn (process-fn proc)))
      (fn proc-in proc-out proc-error proc-fn)
      (close-output-port proc-in)
      (close-input-port proc-out)
      (close-input-port proc-error))))


; svn update

(define (svn-update-command update-path)
  (format "svn update ~A" update-path))

(define (svn-update-fn in out error fn)
  (define (display-port port)
    (let ((l (read-line port 'any)))
      (cond ((eof-object? l)
             (void))
            (else
             (write-string l)
             (newline)
             (display-port port)))))
  (display-port out)
  (display-port error))

(define (svn-update path)
  (svn-process (svn-update-command path) svn-update-fn))